package com.bw.exception;

import com.alibaba.fastjson2.JSON;
import com.bw.utils.JsonOutput;
import com.bw.utils.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class MyGlobalExceptionHandler {


    /**
     * 捕获自定义异常
     * @param e
     * @return
     */
    @ResponseBody
    @ExceptionHandler(MyRuntimeException.class)
    public R errorExceptionHandler(Exception e){
        e.printStackTrace();
        return R.ERROR(500,e.getMessage());
    }

    /**
     * 捕获其他异常
     * @param e
     * @return
     */
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public R exceptionHandler(Exception e){

        e.printStackTrace();
        return R.ERROR(500,"系统出现问题,请联系管理员");
    }

}
